import { registerMapItem, type MapItem, addMapItemInfoView } from '@/map-item'
import { entityMapItem, entityMapItemType } from '../base'
import type { Waypoint } from '../waypoint'
import type { ATSRoute } from './types'
import { atsRouteLayer } from './map'
import { highlightATSRouteFeatures } from './feature'
import { atsRouteIndex } from './atsroute-index'
import { ATSRouteInfoVue, WaypointATSRouteList } from './info'

export function initATSRouteMapItems() {
  registerMapItem<ATSRoute>({
    type: entityMapItemType('ATSRoute'),
    typeName: '航路',
    icon: 'mas-icon-ATSRoute',
    getName: (t) => t.id,
    index: {
      enable: () => atsRouteLayer.visible,
      search: (lng, lat, r) => atsRouteIndex.search(lng, lat, r)
    },
    highlight: highlightATSRouteFeatures,
    infoView: ATSRouteInfoVue
  })
  addMapItemInfoView<Waypoint>(entityMapItemType('Waypoint'), WaypointATSRouteList)
}

export function atsRouteMapItem(id: string): MapItem<ATSRoute> {
  return entityMapItem('ATSRoute', id)
}
